<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  var obj = {
    _name: '小红',
    _age: 12
  }
  Object.defineProperties(obj, {
    _name: {
      configurable: true,
      enumerable: true,
    },
    age: {
      configurable: true,
      enumerable: false,
      get: function () {
        console.log('这是age的get方法')
        return this._age
      },
      set: function (val) {
        console.log('这是age的set方法')
        this._age = val
      }
    },
    _sex: {
      configurable: true,
      enumerable: false,
      value: 'nv',
      writable: true
    }
  })
  console.log(obj);
</script>

</html>